home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / as5.zip / DO5.C < prev    next >
Text File  |  1988-04-30  |  4KB  |  216 lines

  1. /*
  2.  *      MC6805 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED   0       /* immediate */
  7. #define IND     1       /* indexed */
  8. #define OTHER   2       /* NOTA */
  9.  
  10.  
  11. char *skip_white();   /* this line added to keep TurboC happy 4/30/88 jec */
  12.  
  13. /*
  14.  *      localinit --- machine specific initialization
  15.  */
  16. localinit()
  17. {
  18. }
  19.  
  20. /*
  21.  *      do_op --- process mnemonic
  22.  *
  23.  *    Called with the base opcode and it's class. Optr points to
  24.  *    the beginning of the operand field.
  25.  */
  26. do_op(opcode,class)
  27. int opcode;    /* base opcode */
  28. int class;    /* mnemonic class */
  29. {
  30.     int     dist;   /* relative branch distance */
  31.     int     amode;  /* indicated addressing mode */
  32.     char    *peek;
  33.  
  34.     /* guess at addressing mode */
  35.     peek = Optr;
  36.     amode = OTHER;
  37.     while( !delim(*peek) && *peek != EOS)  /* check for comma in operand field */
  38.         if( *peek++ == ',' ){
  39.             amode = IND;
  40.             break;
  41.             }
  42.     if( *Optr == '#' ) amode = IMMED;
  43.  
  44.     switch(class){
  45.         case INH:                       /* inherent addressing */
  46.             emit(opcode);
  47.             return;
  48.         case GEN:                       /* general addressing */
  49.             do_gen(opcode,amode);
  50.             return;
  51.         case REL:                       /* short relative branches */
  52.             eval();
  53.             dist = Result - (Pc+2);
  54.             emit(opcode);
  55.             if( (dist >127 || dist <-128) && Pass==2){
  56.                 error("Branch out of Range");
  57.                 emit(lobyte(-2));
  58.                 return;
  59.                 }
  60.             emit(lobyte(dist));
  61.             return;
  62.         case NOIMM:
  63.             if( amode == IMMED ){
  64.                 error("Immediate Addressing Illegal");
  65.                 return;
  66.                 }
  67.             do_gen(opcode,amode);
  68.             return;
  69.         case GRP2:
  70.             if( amode == IND ){
  71.                 do_indexed(opcode+0x20);
  72.                 return;
  73.                 }
  74.             eval();
  75.             Cycles += 2;
  76.             if(Force_byte){
  77.                 emit(opcode);
  78.                 emit(lobyte(Result));
  79.                 return;
  80.                 }
  81.             if(Result>=0 && Result <=0xFF){
  82.                 emit(opcode);
  83.                 emit(lobyte(Result));
  84.                 return;
  85.                 }
  86.             error("Extended Addressing not allowed");
  87.             return;
  88.         case SETCLR:
  89.         case BTB:
  90.             eval();
  91.             if(Result <0 || Result >7){
  92.                 error("Bit Number must be 0-7");
  93.                 return;
  94.                 }
  95.             emit( opcode | (Result << 1));
  96.             if(*Optr++ != ',')error("SYNTAX");
  97.             eval();
  98.             emit(lobyte(Result));
  99.             if(class==SETCLR)
  100.                 return;
  101.             /* else it's bit test and branch */
  102.             if(*Optr++ != ',')error("SYNTAX");
  103.             eval();
  104.             dist = Result - (Old_pc+3);
  105.             if( (dist >127 || dist <-128) && Pass==2){
  106.                 error("Branch out of Range");
  107.                 emit(lobyte(-3));
  108.                 return;
  109.                 }
  110.             emit(lobyte(dist));
  111.             return;
  112.         default:
  113.             fatal("Error in Mnemonic table");
  114.         }
  115. }
  116.  
  117. /*
  118.  *      do_gen --- process general addressing
  119.  */
  120. do_gen(op,mode)
  121. int     op;
  122. int     mode;
  123. {
  124.     if( mode == IMMED){
  125.         Optr++;
  126.         emit(op);
  127.         eval();
  128.         emit(lobyte(Result));
  129.         return;
  130.         }
  131.     else if( mode == IND ){
  132.         do_indexed(op+0x30);
  133.         return;
  134.         }
  135.     else if( mode == OTHER){        /* direct or extended addressing */
  136.         eval();
  137.         if(Force_word){
  138.             emit(op+0x20);
  139.             eword(Result);
  140.             Cycles += 3;
  141.             return;
  142.             }
  143.         if(Force_byte){
  144.             emit(op+0x10);
  145.             emit(lobyte(Result));
  146.             Cycles += 2;
  147.             return;
  148.             }
  149.         if(Result >= 0 && Result <= 0xFF){
  150.             emit(op+0x10);
  151.             emit(lobyte(Result));
  152.             Cycles += 2;
  153.             return;
  154.             }
  155.         else {
  156.             emit(op+0x20);
  157.             eword(Result);
  158.             Cycles += 3;
  159.             return;
  160.             }
  161.         }
  162.     else {
  163.         error("Unknown Addressing Mode");
  164.         return;
  165.         }
  166. }
  167.  
  168. /*
  169.  *      do_indexed --- handle all wierd stuff for indexed addressing
  170.  */
  171. do_indexed(op)
  172. int op;
  173. {
  174.     eval();
  175.     if(!(*Optr++ == ',' && (*Optr == 'x' || *Optr == 'X')))
  176.         warn("Indexed Addressing Assumed");
  177.     if(Force_word){
  178.         if(op < 0x80 ){ /* group 2, no extended addressing */
  179.             emit(op+0x10); /* default to one byte indexed */
  180.             emit(lobyte(Result));
  181.             Cycles += 3;
  182.             return;
  183.             }
  184.         emit(op);
  185.         eword(Result);
  186.         Cycles += 4;
  187.         return;
  188.         }
  189.     Cycles += 3;    /* assume 1 byte indexing */
  190.     if(Force_byte){
  191.         emit(op+0x10);
  192.         emit(lobyte(Result));
  193.         return;
  194.         }
  195.     if(Result==0){
  196.         emit(op+0x20);
  197.         Cycles--;       /* ,x slightly faster */
  198.         return;
  199.         }
  200.     if(Result>0 && Result <=0xFF){
  201.         emit(op+0x10);
  202.         emit(lobyte(Result));
  203.         return;
  204.         }
  205.     if( op < 0x80 ){
  206.         warn("Value Truncated");
  207.         emit(op+0x10);
  208.         emit(lobyte(Result));
  209.         return;
  210.         }
  211.     emit(op);
  212.     eword(Result);
  213.     Cycles++;       /* 2 byte slightly slower */
  214.     return;
  215. }
  216.